package com.cx.java;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cx.java.JdbcUtils;

/**
 * Servlet implementation class DelServlet
 */
@WebServlet("/DelServlet")
public class DelServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DelServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
	response.setCharacterEncoding("UTF-8");
		String id = request.getParameter("id");
	     JdbcUtils ju = JdbcUtils.getInstance();
	   //数据库名待定
	     String sql = "delete from car where id=" + id;
	     int affectedRow = ju.executeUpdate(sql);
	     if(affectedRow > 0) {
	    	 // 删除成功返回首页（是否跳转到成功页面后再跳转到首页）
	    	 response.sendRedirect("/car/CarInfoServlet");
	     } else {
	    	 // 删除失败（跳转到失败页面）
	    	 response.sendRedirect("/car/defeat.jsp");
	     }
	     
	}

	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
